﻿using System;
using System.IO;

namespace Autorun
{
	public enum StartModes
	{
#if DEBUG
		Debug,
#endif
		Service,
		Client,
		Server
	}

	static class ApplicationStartInfo
	{

		// By default, the start mode is Windows NT Service
		static StartModes _startMode = StartModes.Service;
		static string _root;
		static string _instance;

		static ApplicationStartInfo()
		{
			string[] args;
			string arg;
			string[] command;


			// === Parse Command line ==============================================
			args = Environment.GetCommandLineArgs();
			_root = Path.GetDirectoryName(args[0]).ToLower();
			_instance = "default";

			for (int i = 1; i < args.Length; i++)
			{
				arg = args[i].ToLower().Trim().Replace("/", "");
				switch (arg)
				{
#if DEBUG
					case "debug":
						_startMode = StartModes.Debug;
						break;
#endif
					case "client":
						_startMode = StartModes.Client;
						break;
					case "server":
						_startMode = StartModes.Server;
						break;
					default:
						// In service mode, I could install many instances on the same
						// server
						command = arg.Split('=');
						if (command.Length == 2)
							switch (command[0].ToLower().Trim())
							{
								case "instance":
									_instance = command[1];
									break;
							}
						break;
				}
			}
		}

		public static StartModes StartMode
		{
			get { return _startMode; }
		}

		public static string RootDirectory
		{
			get { return _root; }
		}

		public static string Instance
		{
			get { return _instance; }
		}

	}
}
